<template>
	<view class="gridBox">
		<u-skeleton v-if="gridData.length==0" :loading="true" :animate="true" rows='3' rowsWidth="100%"
			:title='false'></u-skeleton>
		<view v-else class="grid-item" v-for="(item,index) in gridData" :key="index" @click="goPage(index)">
			<view class="imgBox">
				<view class="img" :style="{ backgroundImage: 'url(https://api.jingkakeji.com/' + item.image + ')' }">
				</view>
			</view>
			<view class="text">
				{{item.name}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		Menu
	} from "../../api/api.js"
	export default {
		data() {
			return {
				gridData: []
			}
		},
		mounted() {
			this.onMenus()
		},
		methods: {
			async onMenus() {
				let res = await Menu()
				if (res.data.code == 1) {
					// console.log(res.data.data);
					this.gridData = res.data.data
				}
			},
			//跳转分类
			goPage(index) {
				uni.setStorageSync('gridIndex', index)
				uni.switchTab({
					url: '/pages/classify/classify'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.gridBox {
		width: 100%;
		height: 100%;
		display: flex;
		flex-wrap: wrap;
		justify-content: start;
		align-items: center;

		.grid-item {
			width: 142rpx;
			height: 180rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-evenly;

			.imgBox {
				width: 100rpx;
				height: 100rpx;
				// background-image: linear-gradient(to bottom, #dedede, white);
				border-radius: 50%;
				display: flex;
				justify-content: center;
				align-items: center;

				.img {
					width: 70rpx;
					height: 70rpx;
					background-size: contain;
					background-position: center;
					background-repeat: no-repeat;
				}
			}

			.text {
				font-size: 20rpx;
			}
		}
	}
</style>